public class Solution1813 {
    public boolean areSentencesSimilar(String sentence1, String sentence2) {
        String[] s1=sentence1.split(" ");
        String[] s2=sentence2.split(" ");
        if (s1.length<s2.length){
            String[] t=s1;
            s1=s2;
            s2=t;
        }
        int l=0,r=s2.length-1;
        while (l<s2.length && s1[l].equals(s2[l])){
            l++;
        }
        while (r>=0 && s1[s1.length-(s2.length-r)].equals(s2[r])){
            r--;
        }
        return l>r;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1813().areSentencesSimilar("My name is Haley","My Haley"));
    }
}
